package com.hospital.hms.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.hutool.core.bean.BeanUtil;
import com.hospital.hms.common.CommonResult;
import com.hospital.hms.controller.form.SelectMedicalDeptSubByPageForm;
import com.hospital.hms.service.MedicalDeptSubService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/medical/dept/sub")
@Tag(name = "MedicalDeptSubController", description = "诊室管理接口")
public class MedicalDeptSubController {
    @Autowired
    private MedicalDeptSubService medicalDeptSubService;
    @Operation(summary = "分页诊室查询接口")
    @PostMapping("/selectConditionByPage")
    @SaCheckPermission(value = {"ROOT", "MEDICAL_DEPT:UPDATE"}, mode = SaMode.OR)
    public CommonResult selectConditionByPage(@Valid @RequestBody SelectMedicalDeptSubByPageForm
                                                      selectMedicalDeptSubByPageForm){
        Map<String, Object> param = BeanUtil.beanToMap(selectMedicalDeptSubByPageForm);
        Integer page = selectMedicalDeptSubByPageForm.getPage();
        Integer length = selectMedicalDeptSubByPageForm.getLength();
        Integer start =(page-1)*length;
        param.put("start",start);
        return CommonResult.ok().put(CommonResult.RETURN_RESULT,medicalDeptSubService.selectConditionByPage(param));
    }
}
